package com.larosa.practice.domain;

import com.larosa.practice.fruitenum.Fruit;
import com.larosa.practice.strategy.NoPromotionStrategy;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.math.BigDecimal;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * @Author: larosa
 * @Description: 测试动态调整水果的价格
 * @DateTime: 2025/2/10 18:26
 **/
@SpringBootTest
public class SupermarketTest5 {
    @Test
    void testDynamicPriceAdjustment(){
        //苹果的单价调整为10，购买苹果2斤  2*10 = 20
        Supermarket supermarket = new Supermarket(new NoPromotionStrategy());
        int appleQuantity = 2;
        int strawberryQuantity = 0;
        int mangoQuantity = 0;
        // 调整苹果价格
        BigDecimal newApplePrice = new BigDecimal("10");
        supermarket.setFruitPrice(Fruit.APPLE, newApplePrice);
        BigDecimal expected = newApplePrice.multiply(BigDecimal.valueOf(appleQuantity));
        System.out.println("预期花费：" + expected + "元");
        BigDecimal actual = supermarket.calculateTotalPrice(appleQuantity, strawberryQuantity, mangoQuantity);
        System.out.println("实际花费：" + actual + "元");
        assertEquals(expected, actual);
    }
}
